package org.shuma.user.mng.controller;

import org.shuma.user.mng.domain.vo.AuthVo;
import org.shuma.user.mng.service.UserService;
import org.shuma.user.mng.vaild.group.AuthGroup;
import org.shuma.user.utils.Result;
import org.shuma.user.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author zhao haitao
 * @date 2024/06/16 7:54 PM
 */
@Controller
@RequestMapping("/user")
@Validated
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("")
    public Result<UserVo> getUserInfo(@RequestHeader("Authorization") @Valid @NotBlank(message = "token不能为空") String token) {
        return userService.getUserInfoByToken(token);
    }

    @PutMapping("/password")
    public Result updatePassword(@Validated(AuthGroup.updatePassword.class) @RequestBody AuthVo auth) {
        return userService.updatePassword(auth);
    }
}
